<template>
	<view>
		<u-navbar title="我的优惠券" :autoBack="true" :placeholder="true"></u-navbar>

		<view class="coupon-sec-body" :class="isIphoneX ? 'padding-bottom' : ''">
			<view class="coupon-list">
				<view class="coupon-item" v-for="(item, index) in couponList" :key="index"
					@click="jumpGetCoupon(item.coupon_type_id)">
					<view class="coupon-item-box">
						<view class="coupon-pic">
							<image mode="aspectFit" src="../../static/images/other/yhq.png"></image>
						</view>
						<view class="coupon-item-con">
							<view class="coupon-item-name">
								¥
								<text class="num">{{ item.cost }}</text>
								满{{ item.limitcost }}可用
							</view>
							<text class="coupon-item-desc">{{ item.name }}(&nbsp;全场商品可使用&nbsp;)</text>
						</view>
						<view  class="coupon-item-operation">
							<text>领取完成</text>
						</view>
					</view>


				</view>
				<uni-load-more :status="status" v-if="couponList.length > 0 && pageCount > 1" />
			</view>
			<!-- <loading-cover ref="loadingCover"></loading-cover> -->
			<view v-if="isEmpty && couponList.length == 0" class="empty">
				<view class="iconfont iconwenzhangchaxun"></view>
				<text class="ns-text-color-gray">暂无优惠券</text>
				<button type="primary" @click="goIndex()">去首页逛逛吧</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				uid: wx.getStorageSync('userId'),
				isEmpty: false,
				couponList: [],
				pageIndex: 1,
				status: 'loading',
				pageCount: 0,
				indent: false, //防止初始化数据时，触发上拉加载
				isIphoneX: false //判断手机是否是iphoneX以上
			};
		},
		onReachBottom() {
			if (!this.indent) return;
		},
		onLoad() {
			uni.getSystemInfo({
				success: res => {
					if (res.model.search('iPhone X') != -1) {
						this.isIphoneX = true;
					}
				}
			});
		},
		onShow() {
			this.getmycouponlist();
		},
		// mixins: [http],
		methods: {
			async getmycouponlist() {
				let res = await this.$api.getmycouponlist({
					uid: this.uid
				});
				console.log(res);

				this.couponList = res.data.data;
			},

			//去首页
			goIndex() {
				this.$util.redirectTo('/pages/index/index/index', {}, 'tabbar');
			},
			jumpGetCoupon(id) {
				this.$util.redirectTo('/pages/goods/coupon_receive/coupon_receive', {
					coupon_type_id: id
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.coupon-item {
		margin-top: 30rpx;
		padding: 30rpx;
		background-color: #fff;

		.coupon-item-box {
			&.completion-collection {
				// background-color: $ns-bg-color-gray;

				view {
					color: #999 !important;
				}
			}

			&:after {
				content: '';
				position: absolute;
				top: -14rpx;
				left: 514rpx;
				z-index: 3;
				width: 30rpx;
				height: 30rpx;
				background-color: #fff;
				border-radius: 50%;
			}

			&:before {
				content: '';
				position: absolute;
				bottom: -14rpx;
				left: 514rpx;
				z-index: 3;
				width: 30rpx;
				height: 30rpx;
				background-color: #fff;
				border-radius: 50%;
			}

			position: relative;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 16rpx;
			border-radius: 12rpx;
			// background-color: lighten($base-color, 45%);

			.coupon-item-con {
				width: 316rpx;
				margin-right: auto;
				padding-right: 20rpx;
				height: 156rpx;
				border-right: 1px dashed #fff;
				line-height: 1;
				// font-size: $ns-font-size-base;

				text {
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					display: inherit;
				}
			}

			.coupon-item-operation {
				margin-right: 10rpx;
				color: #111;
				// color: $base-color;
				// font-size: $ns-font-size-base;
			}

			.coupon-item-name {
				margin-top: 14rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.num {
				margin-left: 4rpx;
				margin-right: 10rpx;
				// font-size: $ns-font-size-lg + 12rpx;
				font-weight: 600;
				display: inline-block !important;
				overflow: initial !important;
			}
		}
	}

	.padding-bottom {
		padding-bottom: 68rpx !important;
	}

	.coupon-pic {
		width: 144rpx;
		height: 144rpx;
		margin-right: 30rpx;

		image {
			width: 144rpx;
			height: 144rpx;
		}
	}
</style>